<?php

namespace App\Services;

use App\Models\AdminResourceCategory;

class AdminResourceCategoryService extends BaseService
{
    /**
     *查询所有后台资源分类
     * @return array
     */
    public function listAll(): array
    {
        $result = AdminResourceCategory::query()->get();
        if ($result->count() >0){
            return $result->toArray();
        }
        return [];
    }

    /**
     * 添加后台分类资源
     * @param $data
     * @return bool
     */
    public function create($data): bool
    {
        try {
            $result = AdminResourceCategory::query()->create($data);
            if ($result) {
                return true;
            }
            return false;
        }catch (\Exception $exception) {
            return false;
        }
    }

    /**
     * 根据ID修改资源分类信息
     * @param $data
     * @param $id
     * @return bool
     */
    public function updateById($data,$id): bool
    {
        try {
            $result = AdminResourceCategory::query()->where('id','=',$id)->update($data);
            if ($result) {
                return true;
            }
            return false;
        }catch (\Exception $exception) {
            return false;
        }
    }

    /**
     * 根据ID删除分类信息
     * @param $id
     * @return bool
     */
    public function deleteById($id): bool
    {
        try {
            $result = AdminResourceCategory::query()->where('id','=',$id)->delete();
            if ($result) {
                return true;
            }
            return false;
        }catch (\Exception $exception) {
            return false;
        }
    }
}
